<?php
/**
 * 登录
 */

class Admin_Page_Login extends Admin_Page_Abstract
{
    public function validate(ME_Request $input, ME_Response $output)
    {
        return true;
    }

    public function doDefault(ME_Request $input, ME_Response $output)
    {
        $output->errorMsg = $input->get("msgCode");
        //产生验证码
        $checkCode   = new ME_Seccode();
        $authKey     = $checkCode->getAuthKey();
        $rand        = rand(100000, 999999);
		$output->checkCodeHide  = $rand;
        $output->setTemplate("Login");
    }
    public function doLogOut(ME_Request $input, ME_Response $output){
        Libs_UcUser::clearAdminLoginStatus($input,$output);
        echo '<script>window.location.href="index.php?c=Login";</script>';
        exit;
    }
    public function doLogin(ME_Request $input, ME_Response $output){
        $userName = trim($input->post("userName"));
        $passWord = trim($input->post("passWord"));
        $checkCodeHide = (int)$input->post("checkCodeHide");
        $checkCode     = trim($input->post("checkcode"));


        //获得真正码
        $checkCodeObj   = new ME_Seccode();
        $trueCode    = $checkCodeHide - 10;
        $checkCodeObj->seccodeconvert($trueCode);
        if(strtoupper($checkCode) != $trueCode){
            $this->goRetry('验证码错误！');
        }

        $paramArr = array('username'=>$userName,'password'=>$passWord);

        $loginResult = Libs_UcUser::checkAdminLogin($userName,$passWord);

        if($loginResult){
            echo '<script>window.location.href="index.php?c=Admin"</script>';
            exit;
        }else{//登录失败
            $this->goRetry($loginResult['msg']);
        }

    }
    //注册
    public function goRetry($code){
        header("Location: ?c=Login&msgCode=" . urlencode($code));
        exit;
    }

}

